<?php

namespace Biz\model\bigData;


class TStatsignSync extends \Doraemon\pockets\datebase\BaseDbModel
{
    const _CONFIG_FILE_ = 'db_bigdata_online';

    const _CONFIG_SELECT_ = 'hhz_tracking';

    const _DATABASE_ = 'hhz_tracking';

    const _TABLE_NAME = 't_statsign_sync';


    public static function generateFile(): array
    {
        $list = self::select('*');
        $response = [];
        $const = '';
        $constMap = [];
        if ($list) {
            foreach ($list as $v) {
                $response[$v['module']][$v['version']] = $v['statsign_json'];
                $module = $v['module'];
                $constModule = str_replace('-', '_', $module);
                $constModule = strtoupper($constModule);
                if (empty($constMap[$module])) $const .= PHP_EOL . "    const MODULE_{$constModule} = '$module';";
                $constMap[$module] = true;
            }
        }

        //配置排序
        foreach ($response as $k => $config) {
            krsort($config);
            $response[$k] = $config;
        }

        $conf = var_export($response, true);

        $const .= PHP_EOL . "    const STATIC_CONF = $conf;";

        if (PHP_SAPI == "cli" && $response) {
            echo PHP_EOL, "======== CONST 覆盖 \Doraemon\pockets\constInterface\statSign\AutoPlatformModule.php ========", PHP_EOL;
            echo PHP_EOL, "======== 检查类常量定义冲突,提交代码完成配置 ========", PHP_EOL;
            echo $const, PHP_EOL;
        }

        return $response;
    }

}